From: Rob Church Date: Thu, 22 Jun 2006 12:19:55 +0000 (+0000) Subject: Introduce optional (off by default) language selector bar for user login and registra... X-Git-Tag: 1.31.0-rc.0~56693 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=60c83c3b0af22ef7a0ba41a27adc19f9a5e11601;p=lhc%2Fweb%2Fwiklou.git Introduce optional (off by default) language selector bar for user login and registration.Customisable via the "loginlanguagelinks" message, the links will preserve "returnto" values. If the user creates an account while using such a link, then the language in use will be saved as their language preference. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f6b49f5d63..9a3413ef23 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -537,6 +537,10 @@ Some default configuration options have changed: * (bug 6392) Fix misbehaving
in preferences form * Add translated magic words to Hebrew localization * (bug 6396) Change name for Chuvash language +* Introduce optional (off by default) language selector bar for user login and registration. + Customisable via the "loginlanguagelinks" message, the links will preserve "returnto" + values. If the user creates an account while using such a link, then the language in use + will be saved as their language preference. == Compatibility == diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 9ef31e28ff..053798f06e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -663,6 +663,13 @@ $wgMsgCacheExpiry = 86400; # Whether to enable language variant conversion. $wgDisableLangConversion = false; +/** + * Show a bar of language selection links in the user login and user + * registration forms; edit the "loginlanguagelinks" message to + * customise these + */ +$wgLoginLanguageSelector = false; + # Whether to use zhdaemon to perform Chinese text processing # zhdaemon is under developement, so normally you don't want to # use it unless for testing diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 6a549e2d4e..a951d2b1c2 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -27,7 +27,7 @@ function wfSpecialUserlogin() { class LoginForm { var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword; - var $mLoginattempt, $mRemember, $mEmail, $mDomain; + var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage; /** * Constructor @@ -53,6 +53,7 @@ class LoginForm { $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' ); $this->mAction = $request->getVal( 'action' ); $this->mRemember = $request->getCheck( 'wpRemember' ); + $this->mLanguage = $request->getText( 'uselang' ); if( $wgEnableEmail ) { $this->mEmail = $request->getText( 'wpEmail' ); @@ -141,6 +142,12 @@ class LoginForm { if( $u == NULL ) return; + # If we showed up language selection links, and one was in use, be + # smart (and sensible) and save that language as the user's preference + global $wgLoginLanguageSelector; + if( $wgLoginLanguageSelector && $this->mLanguage ) + $u->setOption( 'language', $this->mLanguage ); + # Save user settings and send out an email authentication message if needed $u->saveSettings(); if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) @@ -533,6 +540,13 @@ class LoginForm { $template->set( 'userealname', $wgAllowRealName ); $template->set( 'useemail', $wgEnableEmail ); $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember ); + + global $wgLoginLanguageSelector; + if( $wgLoginLanguageSelector ) { + $template->set( 'languages', $this->makeLanguageSelector() ); + if( $this->mLanguage ) + $template->set( 'uselang', $this->mLanguage ); + } // Give authentication and captcha plugins a chance to modify the form $wgAuth->modifyUITemplate( $template ); @@ -609,5 +623,40 @@ class LoginForm { $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) ); } + + /** + * Produce a bar of links which allow the user to select another language + * during login/registration but retain "returnto" and certain form values + * + * @return string + */ + function makeLanguageSelector() { + $msg = wfMsgForContent( 'loginlanguagelinks' ); + if( $msg != '' && $msg != '<loginlanguagelinks>' ) { + $langs = explode( "\n", $msg ); + $links = array(); + foreach( $langs as $lang ) { + $lang = trim( $lang, '* ' ); + $parts = explode( '|', $lang ); + $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] ); + } + return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : ''; + } else { + return ''; + } + } + + function makeLanguageSelectorLink( $text, $lang ) { + global $wgUser; + $self = Title::makeTitle( NS_SPECIAL, 'Userlogin' ); + $attr[] = 'uselang=' . $lang; + if( $this->mType == 'signup' ) + $attr[] = 'type=signup'; + if( $this->mReturnTo ) + $attr[] = 'returnto=' . $this->mReturnTo; + $skin =& $wgUser->getSkin(); + return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) ); + } + } ?> diff --git a/includes/templates/Userlogin.php b/includes/templates/Userlogin.php index 58d99207b9..cc797f9fe1 100644 --- a/includes/templates/Userlogin.php +++ b/includes/templates/Userlogin.php @@ -31,6 +31,7 @@ class UserloginTemplate extends QuickTemplate {

msg('login') ?>

msgWiki('loginprompt') ?>
+ haveData( 'languages' ) ) { ?> @@ -79,6 +80,7 @@ class UserloginTemplate extends QuickTemplate {
+haveData( 'uselang' ) ) { ?>
msgWiki( 'loginend' ); ?>
@@ -105,6 +107,7 @@ class UsercreateTemplate extends QuickTemplate {

msg('createaccount') ?>

html('header'); /* pre-table point for form plugins... */ ?> + haveData( 'languages' ) ) { ?> @@ -200,6 +203,7 @@ class UsercreateTemplate extends QuickTemplate { } ?> +haveData( 'uselang' ) ) { ?>
msgWiki( 'signupend' ); ?>
diff --git a/languages/Messages.php b/languages/Messages.php index d855110d6f..daa8e78e25 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -2021,7 +2021,17 @@ Please confirm that really want to recreate this page.', # Please don't localise this 'catseparator' => '|', -); +'loginlanguagelabel' => 'Language: $1', + +# Don't duplicate this in translations; defaults should remain consistent +'loginlanguagelinks' => "* Deutsch|de +* English|en +* Esperanto|eo +* Français|fr +* Español|es +* Italiano|it +* Nederlands|nl", +); ?> diff --git a/skins/MonoBook.php b/skins/MonoBook.php index d4c6638519..67b2e38209 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -56,7 +56,7 @@ class MonoBookTemplate extends QuickTemplate { html('headlinks') ?> <?php $this->text('pagetitle') ?> - + data['printable']) ) { ?>media="print" href="text('stylepath') ?>/common/commonPrint.css" /> diff --git a/skins/monobook/main.css b/skins/monobook/main.css index 2de20bf75f..9960c8f8cb 100644 --- a/skins/monobook/main.css +++ b/skins/monobook/main.css @@ -1098,7 +1098,7 @@ div#userlogin .captcha { } -#userloginprompt { +#userloginprompt, #languagelinks { font-size: 85%; }